package com.yyq.gxdc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yyq.gxdc.entity.Dish;
import com.yyq.gxdc.mapper.DishMapper;
import com.yyq.gxdc.service.IDishService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class DishServiceImpl extends ServiceImpl<DishMapper, Dish> implements IDishService {
    @Resource
    private DishMapper dishMapper;

    @Override
    public PageInfo<Dish> findPage(Dish conditioin, int pageNum, int pageSize) {
        return PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> {
            dishMapper.find(conditioin);
        });
    }
    @Override
    public int add(Dish dish) {
        return dishMapper.insert(dish);
    }
    @Override
    public Dish findById(Integer id) {
        return dishMapper.findById(id);
    }

    @Override
    public Dish getDetailByRid(Integer rid){
        Dish dish = dishMapper.findById(rid);

        return dish;
    };

    @Override
    public int update(Dish dish) {
        return dishMapper.updateById(dish);
    }
    @Override
    public int delete(Integer id) {
        return dishMapper.deleteById(id);
    }

    @Override
    public IPage<Dish> getAllDish(Page<Dish> page, Dish conditioin){
        return dishMapper.getAllDish(page,conditioin);
    };
}

